package cn.jsj.hzu.qm.facecloud.user.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import cn.jsj.hzu.qm.facecloud.user.dao.KeyDao;
import cn.jsj.hzu.qm.facecloud.user.pojo.App;
import cn.jsj.hzu.qm.facecloud.user.pojo.Key;

public class KeyDaoImpl implements KeyDao {
	JdbcTemplate jdbcTemplate = null;

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	@Override
	public int getAllKeyNum() {
		String sql = "Select count(*) FROM tb_key";
		try {
			int i = jdbcTemplate.queryForObject(sql, Integer.class);
			return i;
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}

		return -1;
	}

	@Override
	public int addKey(App app) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteKeyByKeyId(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateCount(Key key) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Key findKeyById(int id) {
		String sql_query = "SElECT * FROM key WHERE id= ?";
		Key key = (Key) jdbcTemplate.queryForObject(sql_query, new BeanPropertyRowMapper<>(Key.class),
				new Object[] { id });
		return key;
		
	}
	@Override
	public List<Key> findKeysByApp(App app) {
		// TODO Auto-generated method stub
		return null;
	}

}
